(deftemplate number (slot parteIntreaga)(slot parteZecimala))

(assert (number (parteIntreaga 1)(parteZecimala 0)))
(assert (number (parteIntreaga 3)(parteZecimala 7)))
(assert (number (parteIntreaga 4)(parteZecimala 5)))
(assert (number (parteIntreaga 5)(parteZecimala 2)))
(assert (number (parteIntreaga 6)(parteZecimala 3)))
(assert (number (parteIntreaga 7)(parteZecimala 4)))

(defrule printare 
    (number (parteIntreaga ?i) (parteZecimala ?f)) ;vreau sa gasesc in baza de cunostiinte
                                                   ;parteaIntreaga si sa o retin in i si 
                                                   ;parteaZecimala si sa o retin in f
    => 
     (printout t "numarul are partea intreaga " ?i " si partea fractionara " ?f crlf)
      ;crlf = trece pe rand nou
)
; am observat ca memoria de lucru in jess este de tip stiva, ultimul introdus primul afisat 

;(facts)

(deftemplate sumaz (slot parteIntreaga)) ; sumaz= suma intreaga
(assert (sumaz (parteIntreaga 0 )))

(deftemplate sumaf (slot parteZecimala)) ;sumaf= suma fract
(assert (sumaf (parteZecimala 0)))



(defrule adunaIntreg
   ?idnumber<- (number (parteIntreaga ?i)) ; gaseste numar in baza de cunostiinta
   ?idfapt<-(sumaz (parteIntreaga ?s)) ; gaseste suma in baza de cunostiinta 
    =>
    (bind ?s1 (+ ?s ?i)) ; adauga nr si suma la s1

    (modify ?idfapt (parteIntreaga ?s1)) ; modifica parteaIntreaga cu s1
   ; (printout t ?s1 crlf)
     (retract ?idnumber)
 )
; va afisa 7, 7+16=13, 13+5=18, 18+4=22, 22+3=25, 25+1=26, numerele sunt luata in ordine inversa introducerii

(defrule adunaZecimal
   ?idnumber1<- (number (parteZecimala ?f)) ; gaseste numar in baza de cunostiinta
   ?idfapt1<-(sumaf (parteZecimala ?s)) ; gaseste suma in baza de cunostiinta 
    =>
    (bind ?s2 (+ ?s ?f)) ; adauga nr si suma la s2

    (modify ?idfapt1 (parteZecimala ?s2)) ; modifica parteaIntreaga cu s1
   ; (printout t ?s2 crlf)
     (retract ?idnumber1)
 )
; va afisa 7, 7+16=13, 13+5=18, 18+4=22, 22+3=25, 25+1=26, numerele sunt luata in ordine inversa introducerii




(defrule print
    (sumaz (parteIntreaga ?s)) ;cauta in baza de cunostiinte pe s
     =>
    (printout t "suma intreaga este " ?s crlf) ;7+6+5+4+3+1
)

(defrule print2
    (sumaf (parteZecimala ?s));cauta in baza de cunostiinte pe sz
    =>
    (printout t "suma parte zecimala este " ?s crlf)
 )

(run)
(facts)